package com.wxh.bomb.netty.thread.thread.file;

import java.io.FileNotFoundException;

public class WriteThread implements Runnable {
	private int flag;
	private MyFile[] myFiles;
	private boolean finished = false;

	public WriteThread(int flag, MyFile[] myFiles) {
		this.flag = flag;
		this.myFiles = myFiles;
	}

	@Override
	public void run() {
		int count = 0;
		while(count < 20){
			for (int i = 0; i < myFiles.length; i++) {
				if ((myFiles[i].index.get() % 4) == flag) {
					try {
						myFiles[i].writeStr(String.valueOf(flag + 1));
						// System.out.println(myfiles[i].index.get());
						myFiles[i].index.incrementAndGet();
						count++;
					} catch (FileNotFoundException e) {
						e.printStackTrace();
					}
					break;
				}
			}
		}
		// 线程已经写完
		finished = true;
	}
	
	public boolean isFinished(){
		return finished;
	}

}
